import pygame
from pygame.color import *
from pygame.locals import *
import pymunk as pm

import loader
import collisions as ch


pygame.init()
screen = pygame.display.set_mode((800, 600))
clock = pygame.time.Clock()
running = True

pm.init_pymunk()
space = pm.Space()
space.gravity = pm.Vec2d(0, -200)

loader.LoadLevel("a.svg", space)
ch.init(space)

while running:
    for event in pygame.event.get():
        if event.type == QUIT:
            running = False
        elif event.type == KEYDOWN:
            running = False

    screen.fill(THECOLORS["white"])
    
    for obj in loader.GameObjects:
        obj.draw(screen)

    dt = 1.0/60.0
    space.step(dt)

    for obj in loader.RemoveObjects:
        shape = obj
        loader.GameObjects.remove(obj.data)
        if obj.body.mass == pm.inf:
            space.remove_static(obj)
        else:
            space.remove(obj)
    loader.RemoveObjects = []
    pygame.display.flip()
    clock.tick(60)
    pygame.display.set_caption("fps: " + str(clock.get_fps()))
